<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a>首页</a>
        <a>教务</a>
        <a>
          <cite>班级管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" style="float:right;margin-top: 10px;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh"></i> </a>
</div>

<div class="layui-tab layui-tab-card" lay-filter="filter">

    <ul class="layui-tab-title">
        <li class="layui-this">分班排课</li>
        <li>点名</li>
        <li>教室课表</li>
    </ul>

    <div class="layui-tab-content" >
        <div class="layui-tab-item layui-show">
            <div id="wodekehu" class="x-body" class="clear:both;">
                <div class="layui-row"
                     style="padding-left:20px;border-left:1px solid #e5e5e5;border-right:1px solid #e5e5e5;">
                    <div class="layui-form layui-col-md12 x-so layui-form-pane"  lay-filter="form-organization">
                        <div class="layui-input-inline">
                            <select name="campus_id" lay-verify="required" lay-search="">
                                <option value="">选择校区</option>
                                {volist name="campus" id="campu"}
                                <option value="{$campu.id}">{$campu.campus_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <!--
                            <input type="text" name="grades_name" placeholder="请输入班级名称" autocomplete="off" class="layui-input">
                            -->
                            <select name="grades_name" lay-search="">
                                <option value="">请输入班级名称</option>
                                {volist name="grade" id="vo"}
                                <option value="{$vo.grades_name}">{$vo.grades_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" style="width: auto;" placeholder="创建时间" name="grades_date" id="start">
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" id="search">
                                <i class="layui-icon layui-icon-search"></i>筛选</button>
                            <button class="layui-btn layui-btn-warm" id="clear">
                                <i class="layui-icon"></i>重置</button>
                            <button class="layui-btn layui-btn-normal" id="table-add">
                                <i class="layui-icon layui-icon-add-circle-fine"></i>新增班级</button>
                            <button class="layui-btn layui-btn-danger" id="end-course">结业课程</button>
                        </div>
                    </div>
                </div>

                <input type="hidden"  id="room_id">
                <input type="hidden"  id="room_name">
                <script type="text/html" id="grades_name">
                    <a lay-event="grades_infos" class="layui-table-link">{{ d.grades_name }}</a>
                </script>
                <table class="layui-hide" id="LAY_table_user" lay-filter="table"></table>
                <script type="text/html" id="barTable">


                    {{# if(d.status == 1  && d.class_status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled" ><span title="补课班级请前往【排课管理】中添加临时学员">分班<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } else if(d.status == 1  && d.class_status == 0){ }}
                    <a class="layui-btn layui-btn-xs" lay-event="class_assignment"><span title="已分配学员">分班<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } else{ }}
                    <a class="layui-btn layui-btn-xs" lay-event="class_assignment">分班</a>
                    {{# } }}


                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled" ><span title="已开班的班级无法修改排课信息">修改排课<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="change_paike">修改排课</a>
                    {{# } }}


                    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="head_teacher">修改班主任</a>


                    {{# if(d.status == 0){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled" ><span title="已分班才可使用选位功能">排座<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="choice_seat">排座</a>
                    {{# } }}

                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">结业</a>

                </script>


            </div>
        </div>
        <div class="layui-tab-item layui-show" style="visibility: hidden">
            <div id="dm_arrang" class="x-body" class="clear:both;">
                <div class="layui-row"
                     style="padding-left:20px;border-left:1px solid #e5e5e5;border-right:1px solid #e5e5e5;">
                    <div class="layui-form layui-col-md12 x-so layui-form-pane">

                        <div class="layui-input-inline">
                            <select name="campus_id_arrang" lay-verify="required" lay-search="">
                                <option value="">选择校区</option>
                                {volist name="campus" id="campu"}
                                <option value="{$campu.id}">{$campu.campus_name}</option>
                                {/volist}
                            </select>
                        </div>

                        <div class="layui-input-inline">
                            <!--
                            <input type="text" name="class_grades_name" placeholder="班级名称" autocomplete="off" class="layui-input">
                            -->
                            <select name="class_grades_name" lay-search="">
                                <option value="">请输入班级名称</option>
                                {volist name="grade" id="vo"}
                                <option value="{$vo.grades_name}">{$vo.grades_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="course_id" lay-search="">
                                <option value="">请输入课程名称</option>
                                {volist name="course_list" id="vo"}
                                <option value="{$vo.id}">{$vo.course_name}</option>
                                {/volist}
                            </select>
                        </div>

                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" style="width: auto;" placeholder="开课日期" name="class_date_arranging" id="start_arrang">
                        </div>

                        <div class="layui-input-inline">
                            <button class="layui-btn" id="search_arrang">
                                <i class="layui-icon layui-icon-search"></i>筛选</button>
                            <button class="layui-btn layui-btn-danger" id="clear_arrang">
                                <i class="layui-icon"></i>重置</button>
                            <!--
                            <button class="layui-btn" id="table-add">
                                <i class="layui-icon layui-icon-add-circle-fine"></i>新增排课</button>
                                -->
                        </div>
                    </div>
                </div>
                <table class="layui-table" id="datalist_arrang" lay-filter="Event_arrang"></table>
                <script type="text/html" id="name_arrang">
                    <a lay-event="see_info" class="layui-table-link">{{ d.class_grades_name }}</a>
                </script>
                <script type="text/html" id="barTable_arrang">
                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs " lay-event="cancel_dm">撤销上课</a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="dm">点名上课</a>
                    {{# } }}




                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="modify_student">修改上课信息</a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled"><span title="该课节还未【点名上课】无上课信息">修改上课信息<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } }}


                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="change_content">修改上课内容</a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled"><span title="该课节还未【点名上课】无上课内容">修改上课内容<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } }}


                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled" ><span title="已上课班级无法操作【删除】功能">删除<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
                    {{# } }}




                </script>
            </div>
        </div>
        <div class="layui-tab-item layui-show" style="visibility: hidden">
            <form class="layui-form layui-form-pane"  id="class_seat" >

                <script>
                    var jsonroomlist = eval('{$jsonroom}'); //教室列表

                    for(var i = 0 ; i < jsonroomlist.length;){
                        document.write('<div class="layui-form-item">');
                        for(var j = 0; j  < 4; j ++){
                            if((i+j) < jsonroomlist.length){
                                document.write('<div class="layui-inline" >');
                                document.write('<div class="layui-btn layui-btn-lg  layui-btn-primary"  name="divitem"  onclick="on_Choice(this)" style="width: 250px;height: 130px;text-align: center;line-height: 130px;border-width: 3px;">');
                                document.write('<input type="hidden" name="room_id" value="'+jsonroomlist[i+j].room_id +'">');
                                document.write('<input type="hidden" name="pos" value="'+(i+j) +'">');
                                document.write('<span style="color:#1E9FFF;font-size: 18px;">'+jsonroomlist[i+j].room_name+'</span>');
                                if(jsonroomlist[i+j].room_status === 1){
                                    document.write('<span class="layui-badge layui-bg-blue" style="position:absolute;left:5px;top:5px;width:45px;">'+ jsonroomlist[i+j].teacher+'</span>');
                                    document.write('<span class="layui-badge layui-bg-blue" style="position:absolute;left:5px;top:25px;width:45px;" title="'+jsonroomlist[i+j].course_name+'">'+jsonroomlist[i+j].course_name +'</span>');
                                    document.write('<span class="layui-badge" style="position:absolute;right:5px;bottom:5px;width:35px;">占用</span>');
                                }else if(jsonroomlist[i+j].room_status === 0){
                                    document.write('<span class="layui-badge layui-bg-green" style="position:absolute;right:5px;bottom:5px;width:35px;">空闲</span>');
                                }
                                document.write('</div>');
                                document.write('</div>');
                            }else{
                                break;
                            }
                        }
                        document.write('</div>');
                        i = i+4;
                    }
                </script>
                <hr class="layui-bg-green"  style="margin-top:30px;border-bottom: solid 2px green">
                <table class="layui-table" id="datalist" lay-filter="Event"></table>
                <script type="text/html" id="name">
                    <a lay-event="see_info" class="layui-table-link">{{ d.class_grades_name }}</a>
                </script>
                <script type="text/html" id="barTable_table">
                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs " lay-event="cancel_dm">撤销上课</a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="dm">点名上课</a>
                    {{# } }}


                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="modify_student">修改上课信息</a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled"><span title="该课节还未【点名上课】无上课信息">修改上课信息<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } }}


                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="change_content">修改上课内容</a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled"><span title="该课节还未【点名上课】无上课内容">修改上课内容<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } }}

                    {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-disabled" ><span title="已上课班级无法操作【删除】功能">删除<sup><span class="layui-badge-dot" style="position: relative; top: -3px; left: -3px;"></span></sup></span></a>
                    {{# } else { }}
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
                    {{# } }}




                </script>

            </form>
        </div>
    </div>


</div>

<!--底部公共部分-->
{include file="common/footer" /}

<script>

    /*********课表及点名********/
    var tableIns;
    var divs= document.getElementsByName("divitem");  //选中
    if(divs.length > 0){
        $(divs[0]).css({"background-color":"#FFB800"});
    }
    function on_Choice(obj) {
        var id = $(obj).find("input[name='room_id']").val();
        var pos = parseInt($(obj).find("input[name='pos']").val());
        for(var i =0 ; i < divs.length; i ++){
            if(i === pos){
                $(divs[i]).css({"background-color":"#FFB800"});
            }else{
                $(divs[i]).css({"background-color":"white"});
            }

        }

        var field = {};
        field.room_id = id;
        $.ajax({
            url: '/admin/timetable/updatesession',
            method: "post",
            data: field,
            beforeSend: function () {

            },
            success: function (result) {
                if (result.code === 1) {
                    tableIns.reload();
                }

            },
            complete: function () {
            },
            error: function (error) {
                console.log(error)
            }
        });

    }

    //   setTimeout(function(){location.reload()},300000); //指定5分钟刷新一次

    /*************END*************/

    //座位设置
    function setClass_id(id,room_name) {
        $("#room_id").val(id);
        $("#room_name").val(room_name);

    }


    layui.use(['form', 'table','laydate',  'element', 'layer', 'laytpl'], function () {
        var $ = layui.$,
                form = layui.form,
                table = layui.table,
                layer = layui.layer,
                element = layui.element,
                laydate = layui.laydate
        let qtype = "{$qtype}";

        var loading = layer.load();

        element.on('tab(filter)', function(data){
            console.log(this); //当前Tab标题所在的原始DOM元素
            console.log(data.index); //得到当前Tab的所在下标
            console.log(data.elem); //得到当前的Tab大容器

            if(data.index === 1 || data.index === 2){
                document.getElementById("dm_arrang").style.visibility="visible";
                document.getElementById("class_seat").style.visibility="visible";
            }else{
                document.getElementById("dm_arrang").style.visibility="hidden";
                document.getElementById("class_seat").style.visibility="hidden";
            }




        });


        $('#table-add').click(function () {
            if(qtype != 1){
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '选择校区',
                    area: ['50%', '60%'],
                    shadeClose: false,
                    content: "{:url('Grades/campus')}",
                });
            }else{
                let campus_id = "{$campus_id}";
                location.href = "{:url('Grades/add')}?campus_id="+campus_id;
            }
        });
        //数据表格 方法级渲染
        var tableIns_grades = table.render({
            elem: '#LAY_table_user'
            , url: '{:url("Grades/lists")}'
            , method: 'POST'
            , loading: true
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                {field: 'id', title: '班级ID', width: 100, sort: true, fixed: false, align: 'center'
                }, {field: 'course_id', title: '课程ID', width: 300, align: 'center'
                }, {field: 'grades_name', title: '班级名称',style:'cursor: pointer; color:#01AAED;font-weight: bold;', width: 400, align: 'center',templet: '#grades_name'
                }, {field: 'campus_name', title: '归属校区', width: 100, align: 'center'
                }, {field: 'room_id', title: '教室ID', width: 300, align: 'center'
                }, {field: 'course_name', title: '课程名称', width: 300, align: 'center'
                }, {field: 'teacher', title: '上课老师', width: 100, align: 'center'
                }, {field: 'headmaster', title: '班主任', width: 100, align: 'center'
                }, {field: 'assistant', title: '助教', width: 100, align: 'center'
                }, {field: 'class_start_date', title: '开班日期', width: 120, align: 'center'
                }, {field: 'class_end_date', title: '结业日期', width: 120, align: 'center'
                }, {field: 'holiday_status', title: '是否跳过节假日?', width: 150, align: 'center'
                }, {field: 'repeat_status', title: '重复类型(周/日)', width: 200, align: 'center'
                }, {field: 'project_num', title: '计划课次(次)', width: 150, align: 'center'
                }, {field: 'class_time_place', title: '上课时间', width: 400, align: 'center'
                }, {field: 'preoccupation', title: '预招人数(人)', width: 150, align: 'center'
                }, {field: 'already_class', title: '已排课次(次)', width: 150, align: 'center'
                }, {field: 'already_arranged', title: '上课进度(次)', width: 150, align: 'center'
                }, {field: 'remarks', title: '备注', width: 100, align: 'center'
                }, {field: 'status_text', title: '是否开班?', width: 100, align: 'center'
                }, {field: 'create_time', title: '创建时间', width: 200, align: 'center'
                }, {fixed: 'right', title: '操作', width: 350, align: 'center', toolbar: '#barTable'}
            ]]
            , height: 'full-180'
            , page: true
            , done: function () {
                $("[data-field='id']").css('display','none');
                //      $("[data-field='status_text']").css('display','none');
                $("[data-field='course_id']").css('display','none');
                $("[data-field='room_id']").css('display','none');

                layer.close(loading);

            }
        });
        //日期
        laydate.render({
            elem: '#start',
            range: true
            ,trigger: 'click'
        });
        table.on('edit(table)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            if(field === 'headmaster'){
                $.post('{:url("Grades/edit")}'
                        ,{
                            'id':data.id,
                            'headmaster':value
                        }
                        ,function(result){
                            if(result.code === 1){
                                location.reload();
                            }
                        });
            }
        });
        //监听工具条
        table.on('tool(table)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'del') { //删除
                layer.confirm('结业将会删除相关班课记录,确定结业吗?', function (index) {
                    $.post("{:url('Grades/del')}", {
                        id: data.id
                    }, function (result) {
                        if (result.code === 1) {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            setTimeout(function () {
                                obj.del(); //删除对应行（tr）的DOM结构
                                location.reload();
                            }, 2000)
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });
            } else if (layEvent === 'paike') {
                location.href = '{:url("Grades/arranging")}?id=' + data.id;
            }else if (layEvent === 'class_assignment') {
                layer.open({
                    type: 2,
                    closeBtn: 2,
                    title: data.grades_name,
                    area: ['95%', '95%'],
                    shadeClose: false,
                    content: "{:url('Grades/class_assignment')}?course_id="+data.course_id  + "&room_id=" + data.room_id + "&course_name=" + data.course_name + "&id=" + data.id + "&campus_id=" + data.campus_id,

                });

            }else if (layEvent === 'change_paike') {  //修改排课
                location.href = '{:url("Grades/change_grades")}?id='+data.id + "&campus_id=" + data.campus_id;
            }else if (layEvent === 'head_teacher') {
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '选择班主任',
                    // btn: ['确定', '取消'],
                    area: ['90%', '90%'],
                    shadeClose: false,
                    content: "{:url('Grades/changeheadmaster')}?id=" + data.id + "&campus_id=" + data.campus_id,
                });
            } else if (layEvent === 'check') {
                var status;
                if (data.status === 0) {
                    status = 1;
                } else {
                    status = 0;
                }
                //激活与禁用状态改变
                $.post("{:url('Grades/classmanage_status')}", {
                    id: data.id,
                    status: status
                }, function (rJson) {
                    if (rJson.code === 1) {
                        layer.msg(rJson.msg, {
                            time: 2000
                        });
                        setTimeout(function () {
                            location.reload();
                        }, 2000)
                    } else {
                        layer.msg(rJson.msg, {
                            icon: 2,
                            time: 2000
                        });
                    }
                }, "json")
            }else if (layEvent === 'choice_seat') {

                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '选择教室选座',
                    // btn: ['确定', '取消'],
                    area: ['30%', '40%'],
                    shadeClose: false,
                    content: "{:url('Grades/choice_room')}?id=" + data.id,
                    end:function () {
                        var room_id = $("#room_id").val();
                        var room_name =     $("#room_name").val();
                        if(room_id == '' || room_id.length <= 0 || room_name == '' || room_name <= 0){
                            return;
                        }
                        var url = '{:url("Classroom/seat_selection")}?id='+room_id + '&class_subject_id='+data.id + "&campus_id=" + data.campus_id;
                        layer.open({
                            type: 2,
                            skin: 'layui-layer-lan',
                            closeBtn: 2,
                            title: '('+room_name+')'+'&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;'+'选座',
                            // btn: ['确定', '取消'],
                            area: ['90%', '95%'],
                            shadeClose: false,
                            content: url,
                            cancel: function(index, layero){
                                location.reload();

                                return false;
                            }
                        });

                    }
                });

            }else if(layEvent === 'grades_infos') {   //点击班级名称

                location.href = "{:url('Arranging/arrang_course')}?grades_id="+data.id + '&grades_status='+1+"&campus_id=" + data.campus_id;;
            }
        });
        //搜索项
        $('#search').click(function () {
            var field = {};
            // field.status = $('select[name=status] option:selected').val();
            field.grades_name = $('select[name=grades_name]').val();
            var create_date_rang = $('input[name=grades_date]').val();
            field.campus_id = $('select[name=campus_id] option:selected').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }

            console.log(field);
            tableIns_grades.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });//清除
        $('#clear').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns_grades.reload({
                where: {
                    'grades_name': '',
                    'grades_date':'',
                    'campus_id':'',
                    // 'status': '',
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //结业课程
        $('#end-course').click(function () {
            layer.open({
                skin: 'layui-layer-lan',
                type: 2,
                closeBtn: 2,
                title: '已结业课程',
                area: ['98%', '95%'],
                shadeClose: false,
                content: "{:url('grades/end_grades')}"
            });
        });

        /*********教室课表********/
        //方法级渲染
        tableIns = table.render({
            elem: '#datalist'
            , url: '{:url("Timetable/getlists")}'
            , method: 'POST'
            , loading: true
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                {field: 'id', title: 'ID', width: 100, align: 'center'
                },{field: 'class_grades_name', title: '班级名称', width:300, align: 'center',templet: '#name'
                }, {field: 'teacher', title: '上课老师', width: 120, align: 'center'
                }, {field: 'class_time', title: '上课时间', width: 300, align: 'center'
                }, {field: 'duration', title: '时长', width: 100, align: 'center'
                }, {field: 'status_text', title: '状态', width: 150, align: 'center'
                }, {field: 'actual_number', title: '实到人数', width: 100, align: 'center'
                },{fixed: 'right', title: '操作', width: 360, align: 'center', toolbar: '#barTable_table'}
            ]]
            , height: 'full-180'
            , page: true
            , done: function () {
                $("[data-field='id']").css('display','none');
                layer.close(loading);

            }
        });
        //监听工具条
        table.on('tool(Event)', function (obj) {
            var data = obj.data; //获得当前行数据
            console.log(data)
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'dm') { //查看
                var title = '点名上课';
                if(data.class_grades_name.indexOf("补课班级") != -1){
                    title = '点名上课【补课】';
                }
                layer.open({
                    skin: 'layui-layer-lan',
                    type: 2,
                    closeBtn: 2,
                    title: title,
                    area: ['98%', '95%'],
                    shadeClose: false,
                    content: "{:url('Arranging/roll_call')}?id="+data.id + '&campus_id='+ data.campus_id,
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        body.find("input[name='grades_name']").val(data.class_grades_name);
                        body.find("input[name='class_time']").val(data.class_date);
                    },
                    cancel: function(index, layero){
                        var field = {};
                        field.id = data.id;
                        $.ajax({
                            url: '/admin/arranging/close',
                            method: "post",
                            data: field,
                            beforeSend: function () {
                                isLoad = layer.load(0, {
                                    shade: false
                                }); //0代表加载的风格，支持0-2
                            },
                            success: function (result) {
                                layer.msg(result.msg);
                                if (result.code === 1) {
                                    layer.close(index)
                                    tableIns.reload();

                                }

                            },
                            complete: function () {
                                layer.close(isLoad)
                            },
                            error: function (error) {
                                console.log(error)
                            }
                        });
                        return false;
                    },

                    end:function () {

                        tableIns.reload();
                    }

                });
            }else if(layEvent === 'del'){
                layer.confirm('真的删除该节课么?', function (index) {
                    $.post("{:url('Arranging/class_del')}", {
                        id: data.id
                    }, function (result) {
                        if (result.code === 1) {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            //    tableIns.reload();
                            location.reload();
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });

            }else if(layEvent === 'change_content'){  //修改上课内容

                layer.open({
                    skin: 'layui-layer-lan',
                    type: 2,
                    closeBtn: 2,
                    title: '修改上课内容',
                    area: ['50%', '65%'],
                    shadeClose: false,
                    content: "{:url('Arranging/get_content')}?id="+data.id + '&campus_id='+ data.campus_id,
                });

            }else if(layEvent === 'cancel_dm'){     //撤消排课
                layer.confirm('真的撤销该节课么?', function (index) {
                    $.post("{:url('Arranging/cancel_grades')}", {
                        id: data.id
                    }, function (result) {
                        if (result.code === 1) {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            tableIns.reload();

                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });
            }else if(layEvent === 'see_info'){
                //修改上课信息

            }else if(layEvent === 'modify_student'){

                layer.open({
                    skin: 'layui-layer-lan',
                    type: 2,
                    closeBtn: 2,
                    title: '修改上课信息',
                    area: ['99%', '95%'],
                    shadeClose: false,
                    content: "{:url('Arranging/modify_student')}?id="+data.id + '&campus_id='+ data.campus_id,
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        body.find("input[name='grades_name']").val(data.class_grades_name);
                        body.find("input[name='class_time']").val(data.class_date);
                    },
                    cancel: function(index, layero){

                    },

                    end:function () {

                        tableIns.reload();
                    }

                });

            }
        });
        /**************END**************/


        /*********点名*******************/
        //日期
        laydate.render({
            elem: '#start_arrang',
            range: true
            ,trigger: 'click'
        });

        form.render(null, 'form-organization');
        form.on('submit(form-organization-search)', function (data) {
            let searchLoading = layer.load();
            table.reload('table-organization', {
                url: "{:url('Arranging/lists')}"
                , where: data.field
                , done: function () {
                    layer.close(searchLoading);
                }
            });
            return false;
        });


        //方法级渲染
        var tableIns_arrang = table.render({
            elem: '#datalist_arrang'
            , url: '{:url("Arranging/lists")}'
            , method: 'POST'
            , loading: true
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                {field: 'id', title: 'ID', width: 100, align: 'center'
                }, {field: 'course_class_name', style:'color:#01AAED;font-weight: bold;',title: '课程名称', width: 300, align: 'center'
                }, {field: 'class_grades_name', title: '班级名称', width: 400, align: 'center'
                }, {field: 'class_date', title: '开课日期', width: 120, align: 'center'
                }, {field: 'campus_name', title: '归属校区', width: 100, align: 'center'
                }, {field: 'class_room', title: '教室', width: 100, align: 'center'
                }, {field: 'weekday', title: '星期', width: 100, align: 'center'
                }, {field: 'teacher', title: '上课老师', width: 100, align: 'center'
                }, {field: 'headmaster', title: '班主任', width: 100, align: 'center'
                }, {field: 'assistant', title: '助教', width: 100, align: 'center'
                }, {field: 'class_subject_start', title: '开课时间', width: 120, align: 'center'
                }, {field: 'class_subject_end', title: '下课时间', width: 120, align: 'center'
                }, {field: 'class_length', title: '上课时长', width: 100, align: 'center'
                }, {field: 'actual_number', title: '实到人数?', width: 100, align: 'center'
                }, {field: 'status_text', title: '是否上课?', width: 100, align: 'center'
                }, {field: 'graduation_status_text', title: '状态', width: 100, align: 'center'
                }, {fixed: 'right', title: '操作', width: 360, align: 'center', toolbar: '#barTable_arrang'}
            ]]
            , height: 'full-180'
            , page: true
            , done: function () {
                $("[data-field='id']").css('display','none');
                layer.close(loading);
                /*
                $("table[class=layui-table] tr").each(function(i){
                    if($(this).html().indexOf('结业</div>')>-1){
                        $(this).attr('style','color:red;font-weight: bold;');
                    }
                });
                */
            }
        });
        form.on('switch(sexDemo)', function(obj){
            console.log(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis)
            var status;
            if (obj.elem.checked == true) {
                status = 0;
            } else {
                status = 1;
            }
            //激活与禁用状态改变
            $.post("{:url('Arranging/arranging_check_status')}", {
                id: this.value,
                status: status
            }, function (rJson) {
                if (rJson.code === 0) {
                    layer.msg(rJson.msg, {
                        time: 2000
                    });
                    setTimeout(function () {
                        location.reload();
                    }, 2000)
                } else {
                    layer.msg(rJson.msg, {
                        icon: 2,
                        time: 2000
                    });
                }
            }, "json")
        });
        //搜索项
        $('#search_arrang').click(function () {
            var field = {};
            field.class_grades_name = $('select[name=class_grades_name]').val();
            field.course_id = $('select[name=course_id]').val();
            field.campus_id = $('select[name=campus_id_arrang] option:selected').val();

            var create_date_rang = $('input[name=class_date_arranging]').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }

            console.log(field);
            tableIns_arrang.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
        //清除
        $('#clear_arrang').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns_arrang.reload({
                where: {
                    'class_grades_name': '',
                    'course_id': '',
                    'campus_id_arrang':'',
                    'class_date_arranging':'',
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //监听工具条
        table.on('tool(Event_arrang)', function (obj) {
            var data = obj.data; //获得当前行数据
            console.log(data)
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'dm') { //查看
                var title = '点名上课';
                if(data.class_grades_name.indexOf("补课班级") != -1){
                    title = '点名上课【补课】';
                }
                layer.open({
                    skin: 'layui-layer-lan',
                    type: 2,
                    closeBtn: 2,
                    title: title,
                    area: ['99%', '95%'],
                    shadeClose: false,
                    content: "{:url('Arranging/roll_call')}?id="+data.id + '&campus_id='+ data.campus_id,
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        body.find("input[name='grades_name']").val(data.class_grades_name);
                        body.find("input[name='class_time']").val(data.class_date);
                    },
                    cancel: function(index, layero){
                        var field = {};
                        field.id = data.id;
                        $.ajax({
                            url: '/admin/arranging/close',
                            method: "post",
                            data: field,
                            beforeSend: function () {
                                isLoad = layer.load(0, {
                                    shade: false
                                }); //0代表加载的风格，支持0-2
                            },
                            success: function (result) {
                                layer.msg(result.msg);
                                if (result.code === 1) {
                                    layer.close(index)
                                    tableIns_arrang.reload();

                                }

                            },
                            complete: function () {
                                layer.close(isLoad)
                            },
                            error: function (error) {
                                console.log(error)
                            }
                        });
                        return false;
                    },

                    end:function () {

                        tableIns_arrang.reload();
                    }

                });
            }else if(layEvent === 'del'){
                layer.confirm('真的删除该节课么?', function (index) {
                    $.post("{:url('Arranging/class_del')}", {
                        id: data.id
                    }, function (result) {
                        if (result.code === 1) {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            tableIns_arrang.reload();

                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });

            }else if(layEvent === 'change_content'){  //修改上课内容

                layer.open({
                    skin: 'layui-layer-lan',
                    type: 2,
                    closeBtn: 2,
                    title: '修改上课内容',
                    area: ['50%', '65%'],
                    shadeClose: false,
                    content: "{:url('Arranging/get_content')}?id="+data.id + '&campus_id='+ data.campus_id,
                });

            }else if(layEvent === 'cancel_dm'){     //撤消排课
                layer.confirm('真的撤销该节课么?', function (index) {
                    $.post("{:url('Arranging/cancel_grades')}", {
                        id: data.id
                    }, function (result) {
                        if (result.code === 1) {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            tableIns_arrang.reload();

                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });
            }else if(layEvent === 'see_info'){
                //修改上课信息

            }else if(layEvent === 'modify_student'){

                layer.open({
                    skin: 'layui-layer-lan',
                    type: 2,
                    closeBtn: 2,
                    title: '修改上课信息',
                    area: ['98%', '95%'],
                    shadeClose: false,
                    content: "{:url('Arranging/modify_student')}?id="+data.id + '&campus_id='+ data.campus_id,
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        body.find("input[name='grades_name']").val(data.class_grades_name);
                        body.find("input[name='class_time']").val(data.class_date);
                    },
                    cancel: function(index, layero){

                    },

                    end:function () {

                        tableIns_arrang.reload();
                    }

                });

            }
        });
        /**************END*****************/

    });
</script>